package com.SmartFix.Impl;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.SmartFix.Interface.I_Register;
import com.SmartFix.po.PO_Master;
import com.SmartFix.utils.HibCfg_Ant;

public class IMP_Register implements I_Register{
	Session session = null;
	Transaction ts = null;
	@Override
	public String doRegister(PO_Master master) {
		try{
			session = HibCfg_Ant.getSession();
			ts = session.beginTransaction();
			System.out.println(master.getMst_Account());
			String hql = "from PO_Master m where m.mst_Account=:account";
			Query q = session.createQuery(hql);
			q.setString("account", master.getMst_Account());
			List<PO_Master> list = q.list();
			if(list.size()==0)
				session.save(master);
			else
				return "error";
			ts.commit();
		}catch(Exception e){
			ts.rollback();
			e.printStackTrace();
		}finally{
			session.close();
		}
		return "success";
	}
}
